package com.myh.cc.coom.ranking.viewmodel

import android.content.Intent
import android.view.View
import com.blankj.utilcode.utils.LogUtils.i
import com.myh.cc.base.BaseModel
import com.myh.cc.coom.ranking.adapter.RankingAdapter
import com.myh.cc.coom.ranking.bean.RankingBean
import com.myh.cc.coom.ranking.net.RankingNetControl
import com.myh.cc.coom.ranking.view.RankingDetailsActivity
import com.myh.cc.coom.ranking.view.RankingFragment
import com.myh.cc.databinding.FragmentRankingBinding
import com.myh.cc.util.ConstantUtil
import com.myh.cc.widget.OnItemClickListener

/**
 * des    ：
 * create    ：  mayahao.
 * date   ：  2018/1/13.   ：
 */
class RankingModel: BaseModel<FragmentRankingBinding,RankingNetControl>(),OnItemClickListener {

    lateinit var fragment: RankingFragment
    lateinit var bean: RankingBean

    override fun onCreate() {
        super.onCreate()
        fragment = UI as RankingFragment
    }

    override fun onBeforeRequest(tag: Int) {
    }

    override fun onSuccess(data: Any, tag: Int) {
        bean = data as RankingBean
        initRecycleView(bean)
    }

    override fun onError(errorMag: String, tag: Int) {
        i(errorMag)
    }


    fun getRanking(){

        var  map = HashMap<String,String>()
        map.put("format","json")

        mControl.getRanking(this,"",map,ConstantUtil.requestTagOne)

    }


    private fun initRecycleView(bean: RankingBean){
        val  adapter = RankingAdapter(bean,getContext())
        mBinder.rankingRv.adapter = adapter
        adapter.mListener = this
    }


    override fun onClick(view: View, position: Int) {
        val  intent = Intent(getContext(), RankingDetailsActivity::class.java)
        //intent.putExtra("singermid",bean.to.list[position].Fsinger_mid)
        intent.putExtra("topId",bean.data.topList[position].id.toString())
        fragment.startActivity(intent)
    }

    override fun onItemLongClick(view: View, position: Int) {

    }
}